#Test script of Org Search
#require File.dirname(__FILE__)+'/../lib/testdata.rb'
require File.dirname(__FILE__)+'/../lib/elements/Sales/element_OrgSearch.rb'
require File.dirname(__FILE__)+'/../lib/reporting.rb'
require File.dirname(__FILE__)+'/../lib/std_lib.rb'
require 'watir'
require 'watir/testcase'

class Create_New_Org < Watir::TestCase
    # Open a new enviroment of crmint

    def test_setup
        #  $ie.bring_to_front
        filename  = File.basename(__FILE__).gsub(/\.rb/, "")
        #   @@for="tonytest"
        #  @@search_in="Org Name"

        begin
            $log=Reporting.new(File.dirname(__FILE__)+'/../doc/report/'"",filename)
            if $ie = Watir::IE.find(:title,"ActiveCRM")
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            else
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            end
        rescue
            puts $!
            puts $@
            $log.close unless $log.nil?
        end
    end

=begin
#Data Driven
begin
      org_search_data = SalesData::OrgSearch.new(File.dirname(__FILE__)+"/../../doc/data/testdata.xls")
      @@testdata = org_search_data.get_market_data
    rescue
      puts $!
      puts $@
    ensure
      org_search_data.close unless org_search_data.nil?
    end
=end


    def test_search
        $log.test_notes("Test ActiveCRM")
        $log.test_notes("Start to test Create New Org")
        #Data Driven
        #Element::OrgSearch.search_in_select_list.set(@@search_in[])
        #Element::OrgSearch.for_text_field.set(@@for[rand(@@for.size)])
        #Element::OrgSearch.search_in_select_list.set(@@search_in)
        #Element::OrgSearch.for_text_field.set(@@for)
        Element::OrgSearch.new_org_button.click
        sleep 1
        $ie=Watir::IE.attach(:title,"0")
        Element::CreateNewOrg.country_select_list.select_value("223")
        Element::CreateNewOrg.next_button.click
        sleep 1
        Element::CreateNewOrg.org_name_text_field.set("Tonytest_"+Time.now.strftime("%Y%m%d"))
        Element::CreateNewOrg.state_select_list.select_value("1")
        Element::CreateNewOrg.org_url_text_field.set("www.test.com")
        Element::CreateNewOrg.address1_text_field.set("Keji 2 Road")
        Element::CreateNewOrg.address2_text_field.set("QinFengGe D201")
        Element::CreateNewOrg.city_ text_field.set("Xi'an")
        Element::CreateNewOrg.zip_text_field.set("710075")
        Element::CreateNewOrg.phone_text_field.set("1234567890")
        Element::CreateNewOrg.fax_text_field.set("0123456789")
        Element::CreateNewOrg.email_text_field.set("tonytest@test.com")
        Element::CreateNewOrg.participants_text_field.set("1000")
        Element::CreateNewOrg.census_pop_text_field.set("10000")
        Element::CreateNewOrg.no_of_members_text_field.set("1000")
        Element::CreateNewOrg.next_button.click
        sleep 1
        Element::CreateNewOrg.external_classifier_select_list.select_value("181")
        Element::CreateNewOrg.market1_select_list.select("Educate")
        Element::CreateNewOrg.submarket1_select_list.select("Vocational School")
        Element::CreateNewOrg.type1_select_list.select("Aviation School")
        Element::CreateNewOrg.create_button.click

        $log.test_validate($ie.link(:text,"423199").exists?, "Test 423199 exists or not")
        $log.test_validate($ie.link(:text,"523199").exists?, "Test 523199 exists or not")
        sleep 1
        $ie.close

    end
=begin
  def test_new_org
      $log.test_notes("Start to test New Org")
      Element::OrgSearch.new_org_button.client

  end
=end
  

    def test_reset

    end

    def test_tear_down
        @@for = nil
        @@search_in = nil
    end
end

class NewOrg < Watir::TestCase
    def test_setup
    end

    def test_tear_down
        $log.close unless $log.nil?
    end
end


